//
//  warningSetViewController.m
//  WHB_logist
//
//  Created by 徐国庆 on 15/12/3.
//  Copyright (c) 2015年 turing. All rights reserved.
//

#import "warningSetViewController.h"

@interface warningSetViewController ()<UITableViewDataSource, UITableViewDelegate>

@property(nonatomic, strong)UITableView *tableView;
@property(nonatomic, strong)NSArray *array;

@end

@implementation warningSetViewController

- (instancetype)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        self.array = [NSArray arrayWithObjects:@"碰撞报警", @"超速报警", @"疲劳报警", @"怠速报警", @"区域报警", @"亏电报警", nil];
    }
    return self;
}

- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    [self setTabBarHidden];
}

- (void)viewWillDisappear:(BOOL)animated{
    [super viewWillDisappear:animated];
    [self showTabBar];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.navtitle.text = @"报警设置";
    [self initWithView];
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return 6;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    static NSString *str = @"warningSet";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:str];
    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:str];
    }
    
    UIButton *switchButton = [UIButton buttonWithType:UIButtonTypeCustom];
    switchButton.frame = CGRectMake(kUIScreenWidth - 60, (cell.contentView.frame.size.height - 25) / 2, 50, 25);
    [switchButton setImage:[UIImage imageNamed:@"kai"] forState:UIControlStateNormal];
    [switchButton setImage:[UIImage imageNamed:@"guan"] forState:UIControlStateSelected];
    [switchButton setSelected:NO];
    switchButton.tag = 100 + indexPath.row;
    [switchButton addTarget:self action:@selector(switchButtonAction:) forControlEvents:UIControlEventTouchDown];
    [cell.contentView addSubview:switchButton];
    
    
    cell.textLabel.text = [self.array objectAtIndex:indexPath.row];
    
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    
    
    return cell;
}

- (void)switchButtonAction:(UIButton *)button{
    if (button.selected == NO) {
        [button setSelected:YES];
    } else{
        [button setSelected:NO];
    }
}

- (void)initWithView{
    self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, kUIScreenWidth, kUIScreenHeight) style:UITableViewStylePlain];
    self.tableView.dataSource = self;
    self.tableView.delegate = self;
    self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    [self.view addSubview:self.tableView];
}

////隐藏tabar
//-(void)setTabBarHidden{
//    [[self rdv_tabBarController] setTabBarHidden:YES animated:YES];
//}
//
////隐藏tabar
//-(void)showTabBar{
//    [[self rdv_tabBarController] setTabBarHidden:NO animated:YES];
//}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
